import request from '../utils/request'

export const getArticleList = (page = 1, size = 10) => {
    return request({
        url: '/articles',
        method: 'get',
        params: { page, size }
    })
}

export const getArticleById = (id) => {
    return request({
        url: `/articles/${id}`,
        method: 'get'
    })
}

// 获取热门文章
export const getHotArticles = () => {
    return request({
        url: '/articles/hot',
        method: 'get'
    })
}

// 根据标签获取文章
export function getArticlesByTag(tagId, page = 1, size = 10) {
    return request({
        url: '/articles',
        method: 'get',
        params: {
            tagId,
            page,
            size
        }
    })
}

// 记录文章浏览
export function recordView(articleId) {
    return request({
        url: `/articles/${articleId}/view`,
        method: 'post'
    })
}

// 获取用户收藏的文章列表
export function getFavoriteArticles(page = 1, size = 10) {
    return request({
        url: '/articles/favorites',
        method: 'get',
        params: { page, size }
    })
}

// 获取用户已读的文章列表
export function getReadArticles(page = 1, size = 10) {
    return request({
        url: '/articles/read',
        method: 'get',
        params: { page, size }
    })
}

// 获取用户点赞的文章列表
export function getLikedArticles(page = 1, size = 10) {
    return request({
        url: '/articles/liked',
        method: 'get',
        params: { page, size }
    })
}

// 上传图片
export function uploadImage(formData) {
    return request({
        url: '/upload',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 创建文章
export function createArticle(article) {
    return request({
        url: '/articles',
        method: 'post',
        data: article
    })
}

// 获取用户的文章列表
export function getUserArticles(page = 1, size = 10) {
    return request({
        url: '/articles/user',
        method: 'get',
        params: { page, size }
    })
} 